package com.wxzz.elearing.user.api.app;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.BannerManageDto;
import com.wxzz.elearing.user.dto.DocentInsDto;
import com.wxzz.elearing.user.entity.BannerManage;
import com.wxzz.elearing.user.service.IBannerManageService;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wx-banner-manage")
@Api(tags = "banner图接口")
public class WxBannerManageController {

    @Autowired
    private IBannerManageService bannerManageService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = " 列出平台banner(小程序)", notes = " 列出平台banner(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "wxListBannerManage", method = RequestMethod.POST)
    public ReturnVO<List<BannerManage>> wxListBannerManage( @RequestBody BannerManageDto bannerManageDto) {
        return bannerManageService.listBannerManageByModel(0L, bannerManageDto);
    }

    @ApiOperation(value = "企业banner(小程序)", notes = "根据企业模块列出banner(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listBannerManage", method = RequestMethod.POST)
    public ReturnVO<List<BannerManage>> listBannerManage(@RequestHeader String token, @RequestBody BannerManageDto bannerManageDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return bannerManageService.listBannerManageByModel(jsonObject.getLong("enterpriseId"), bannerManageDto);
    }
}
